﻿using System;
using System.ComponentModel.Composition;
using System.Windows;
using System.Xml;
using NColony.Client.Wpf.ViewModels.Contracts;

namespace NColony.Client.Wpf
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    [Export("RootVisual", typeof(Window))]
    public partial class MainWindow : Window
    {
        private readonly IMainWindowViewModel viewModel;

        /// <summary>
        /// Initializes a new instance of the <see cref="MainWindow"/> class.
        /// </summary>
        /// <param name="viewModel">The view model.</param>
        [ImportingConstructor]
        public MainWindow(IMainWindowViewModel viewModel)
        {
            this.viewModel = viewModel;

            InitializeComponent();

            this.LoadFeedButton.Click += (s, e) =>
                {
                    this.ViewModel.LoadFeedReader(this.FeedAddressInput.Text);
                };
        }

        /// <summary>
        /// Raises the <see cref="E:System.Windows.FrameworkElement.Initialized"/> event. This method is invoked whenever <see cref="P:System.Windows.FrameworkElement.IsInitialized"/> is set to true internally.
        /// </summary>
        /// <param name="e">The <see cref="T:System.Windows.RoutedEventArgs"/> that contains the event data.</param>
        protected override void OnInitialized(EventArgs e)
        {
            base.OnInitialized(e);

            this.FeedAddressInput.Text = "http://ncolony.codeplex.com/Project/ProjectRss.aspx";
            this.DataContext = this.ViewModel.FeedReader.Feed;
        }

        /// <summary>
        /// Gets the view model.
        /// </summary>
        /// <value>The view model.</value>
        public IMainWindowViewModel ViewModel
        {
            get
            {
                return this.viewModel;
            }
        }
    }
}